const SERVICE = require("../../lib/js/service.js");

Page({
  data:{
    is_judgeEditInfo: false
  },
  onLoad(options){
    let _this = this;
    wx.showNavigationBarLoading();
    SERVICE.POST(SERVICE.URL.getRecruitmentInfo,{
      recruitment_id: options.id
    },(status,res)=>{
      wx.hideNavigationBarLoading();  
      console.log("职位详情:",res);
      if(res.data.status == "success"){
        _this.judgeEditInfo(res.data.info.id);                  
        _this.setData({
          positionInfo: res.data.info
        });
      }
    });
  },
  
  /*分享*/
  onShareAppMessage() { },

  //判断是否属于自己的信息
  judgeEditInfo(id){
    let _this = this;
    SERVICE.POST(SERVICE.URL.judgeEditInfo, {
      thirdCookie: wx.getStorageSync("thirdCookie"),
      edit_id: id
    }, (status, res) => {
      if(res.data.status == "success"){
        _this.setData({
          is_judgeEditInfo: true
        });
      }
    });
  },

  /*编辑*/
  compile(){
    let td = this.data;
    wx.navigateTo({
      url: "../job-posted/job-posted?positionInfo=" + JSON.stringify(td.positionInfo)
    });
  },

  /*下线*/
  offine(e){
    console.log(e);
    SERVICE.POST(SERVICE.URL.updateStatus,{
      thirdCookie: wx.getStorageSync("thirdCookie"),
      edit_id: e.currentTarget.dataset.id
    },(status,res)=>{
      if(res.data.status == "success"){
        wx.showToast({
          title: "下线成功",
          icon: "none",
          mask: true
        });
        setTimeout(()=>{
          wx.navigateBack({});
        },2000);
      }else{
        wx.showToast({
          title: "下线成功失败",
          icon: "none",
          mask: true
        });
      }
    });
  },

  /*跳转分享页*/
  navrImg(e){
    wx.navigateTo({
      url:"../join-us-detail/join-us-detail?id=" + e.currentTarget.dataset.id
    });
  }
});